package aigle.idm.diagraph.tp3.diagram_default_root.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

import aigle.idm.diagraph.tp3.Tp3Package;

/**
 * @generated
 */
public class Tp3ElementTypes {

	/**
	 * @generated
	 */
	private Tp3ElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map<IElementType, ENamedElement> elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set<IElementType> KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType LivreRecettes_79 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.LivreRecettes_79"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Recette_1001 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.Recette_1001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Ingredient_1002 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.Ingredient_1002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Vin_1003 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.Vin_1003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Localisation_1004 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.Localisation_1004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Bouteille_2001 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.Bouteille_2001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Compose_3001 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.Compose_3001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType RecetteOrigineRegionale_3002 = getElementType("aigle.idm.diagraph.tp3.diagram_default_root.RecetteOrigineRegionale_3002"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return aigle.idm.diagraph.tp3.diagram_default_root.part.Tp3DiagramEditorPlugin
						.getInstance().getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap<IElementType, ENamedElement>();

			elements.put(LivreRecettes_79,
					Tp3Package.eINSTANCE.getLivreRecettes());

			elements.put(Recette_1001, Tp3Package.eINSTANCE.getRecette());

			elements.put(Ingredient_1002, Tp3Package.eINSTANCE.getIngredient());

			elements.put(Vin_1003, Tp3Package.eINSTANCE.getVin());

			elements.put(Localisation_1004,
					Tp3Package.eINSTANCE.getLocalisation());

			elements.put(Bouteille_2001, Tp3Package.eINSTANCE.getBouteille());

			elements.put(Compose_3001, Tp3Package.eINSTANCE.getCompose());

			elements.put(RecetteOrigineRegionale_3002,
					Tp3Package.eINSTANCE.getRecette_OrigineRegionale());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet<IElementType>();
			KNOWN_ELEMENT_TYPES.add(LivreRecettes_79);
			KNOWN_ELEMENT_TYPES.add(Recette_1001);
			KNOWN_ELEMENT_TYPES.add(Ingredient_1002);
			KNOWN_ELEMENT_TYPES.add(Vin_1003);
			KNOWN_ELEMENT_TYPES.add(Localisation_1004);
			KNOWN_ELEMENT_TYPES.add(Bouteille_2001);
			KNOWN_ELEMENT_TYPES.add(Compose_3001);
			KNOWN_ELEMENT_TYPES.add(RecetteOrigineRegionale_3002);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.LivreRecettesEditPart.VISUAL_ID:
			return LivreRecettes_79;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.RecetteEditPart.VISUAL_ID:
			return Recette_1001;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.IngredientEditPart.VISUAL_ID:
			return Ingredient_1002;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.VinEditPart.VISUAL_ID:
			return Vin_1003;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.LocalisationEditPart.VISUAL_ID:
			return Localisation_1004;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.BouteilleEditPart.VISUAL_ID:
			return Bouteille_2001;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.ComposeEditPart.VISUAL_ID:
			return Compose_3001;
		case aigle.idm.diagraph.tp3.diagram_default_root.edit.parts.RecetteOrigineRegionaleEditPart.VISUAL_ID:
			return RecetteOrigineRegionale_3002;
		}
		return null;
	}

}
